#include <crt_util.h>

GUID StringToGUID(const char* lpString)
{
    GUID guid = {0x00};
    unsigned int Data234[10] = {0x00};
    unsigned int Data12[2] = {0x00};
    char szTemp[GUIDStringLength + 1] = {0x00};
    s_strcpy(szTemp, GUIDStringLength, lpString);

    sscanf(
        szTemp, GUIDFormatString, (unsigned int*)(&guid.Data1), (unsigned int*)(Data12 + 0), (unsigned int*)(Data12 + 1),
        (unsigned int*)(Data234 + 2), (unsigned int*)(Data234 + 3), (unsigned int*)(Data234 + 4), (unsigned int*)(Data234 + 5),
        (unsigned int*)(Data234 + 6), (unsigned int*)(Data234 + 7), (unsigned int*)(Data234 + 8), (unsigned int*)(Data234 + 9));

    guid.Data2 = Data12[0];
    guid.Data3 = Data12[1];

    //{ED660EF7-7D0B-4CBE-8D92-D5F225434464}
    guid.Data4[0] = Data234[2];
    guid.Data4[1] = Data234[3];
    guid.Data4[2] = Data234[4];
    guid.Data4[3] = Data234[5];
    guid.Data4[4] = Data234[6];
    guid.Data4[5] = Data234[7];
    guid.Data4[6] = Data234[8];
    guid.Data4[7] = Data234[9];

    return guid;
};
GUID WStringToGUID(wchar_t* lpString)
{
    GUID guid;
    unsigned int Data234[10] = {0x00};
    unsigned int Data12[2] = {0x00};
    wchar_t szTemp[GUIDStringLength + 1] = {0x00};

    s_wstrcpy(szTemp, GUIDStringLength, lpString);

    swscanf(
        szTemp, GUIDFormatWString, (unsigned int*)(&guid.Data1), (unsigned int*)(Data12 + 0), (unsigned int*)(Data12 + 1),
        (unsigned int*)(Data234 + 2), (unsigned int*)(Data234 + 3), (unsigned int*)(Data234 + 4), (unsigned int*)(Data234 + 5),
        (unsigned int*)(Data234 + 6), (unsigned int*)(Data234 + 7), (unsigned int*)(Data234 + 8), (unsigned int*)(Data234 + 9));

    guid.Data2 = Data12[0];
    guid.Data3 = Data12[1];
    guid.Data4[0] = Data234[2];
    guid.Data4[1] = Data234[3];
    guid.Data4[2] = Data234[4];
    guid.Data4[3] = Data234[5];
    guid.Data4[4] = Data234[6];
    guid.Data4[5] = Data234[7];
    guid.Data4[6] = Data234[8];
    guid.Data4[7] = Data234[9];

    return guid;
};
const char* GUIDToString(const GUID* guid, char* lpGuidBuf)
{
    sprintf(
        lpGuidBuf, GUIDFormatString, (unsigned int)guid->Data1, guid->Data2, guid->Data3, guid->Data4[0], guid->Data4[1], guid->Data4[2],
        guid->Data4[3], guid->Data4[4], guid->Data4[5], guid->Data4[6], guid->Data4[7]);

    return lpGuidBuf;
};
const wchar_t* GUIDToWString(const GUID* guid, wchar_t* lpGuidBuf)
{
    wprintf(
        lpGuidBuf, GUIDFormatWString, (unsigned int)guid->Data1, guid->Data2, guid->Data3, guid->Data4[0], guid->Data4[1], guid->Data4[2],
        guid->Data4[3], guid->Data4[4], guid->Data4[5], guid->Data4[6], guid->Data4[7]);

    return lpGuidBuf;
};

const char* StringToGUIDClassName(const char* strguid, char* lpGuidBuf)
{
    GUID guid = StringToGUID(strguid);
    sprintf(
        lpGuidBuf, GUIDClassName, guid.Data1, guid.Data2, guid.Data3, guid.Data4[0], guid.Data4[1], guid.Data4[2], guid.Data4[3], guid.Data4[4],
        guid.Data4[5], guid.Data4[6], guid.Data4[7]);

    return 0;
}
